package com.zycfc.zsf.boot.util.time;

import java.time.*;
import java.util.*;

public class LocalDateTimeUtil
{
    public static Date convertToDate(final LocalDateTime localDateTime) {
        return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
    }
    
    public static LocalDate convertToLocalDate(final Date date) {
        return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
    }
    
    public static LocalTime convertToLocalTime(final Date date) {
        return date.toInstant().atZone(ZoneId.systemDefault()).toLocalTime();
    }
    
    public static LocalDateTime convertToLocalDateTime(final Date date) {
        return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
    }
    
    public static List<LocalDate> getMiddleDate(final LocalDate begin, final LocalDate end) {
        final List<LocalDate> middleList = new ArrayList<LocalDate>();
        long i;
        for (long length = i = end.toEpochDay() - begin.toEpochDay(); i >= 0L; --i) {
            middleList.add(end.minusDays(i));
        }
        return middleList;
    }
}
